function [areas,areaLabels,intraArea,interArea]=regionalAnalysis(m)

[areas,areaLabels]=areasAndLabels();
[intraArea]=short(m,areas);
[interArea]=long(m,areas);

function [areas,arealabels]=areasAndLabels()

[arealabels]=getAreaLabels();
[areas]=getAreas();

function [arealabels]=getAreaLabels()
arealabels={'laf';'lf';'lfc';'lc';'lcp';'lp';'lpo';'lt';'raf';'rf';'rfc';'rc';'rcp';'rp';'rpo';'rt'};
function [areas]=getAreas()

laf=[22 25 26];
lf=[30 31 32 33];
lfc=[1 2 3];
lc=[8 9 10];
lcp=[15 16 17];
lp=[47 48 49 50];
lpo=[56 57 61];
lt=[39 41 43 45];

raf=[24 28 29];
rf=[35 36 37 38];
rfc=[5 6 7];
rc=[12 13 14];
rcp=[19 20 21];
rp=[52 53 54 55];
rpo=[50 60 63];
rt=[40 42 44 46];

areas={laf;lf;lfc;lc;lcp;lp;lpo;lt;raf;rf;rfc;rc;rcp;rp;rpo;rt};

function [v]=short(M,areas)

v=zeros(1,length(areas));
for i=1:length(areas)
    m=M(areas{i},areas{i}); 
    indx=ones(size(m));
    indx=indx-tril(indx);
    indx=logical(indx);    
     v(i)=mean(m(indx));
end


function [interArea]=long(M,areas)

v=zeros(length(areas),length(areas));
for i=1:length(areas)-1
    for j=i+1:length(areas)
        m=M(areas{i},areas{j});
        s=size(m);
        v(i,j)=mean(reshape(m,s(1)*s(2),1));
    end
end

indx=ones(size(v));
indx=indx-tril(indx);
indx=logical(indx);
%indx=logical(indx);%%warning if phase is 0
interArea=v(indx)';



